package com.hphs.service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.hphs.dao.CategoryDao;
import com.hphs.info.PageInfo;
import com.hphs.model.Category;
import com.hphs.model.CategoryQuery;
import com.hphs.utils.LocalPageInfoutil;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CategoryService {
    //@Autowired
    @Resource
    private CategoryDao categoryDao;

    public List<Category> select(CategoryQuery query){
        if(query.getPageNum() !=null &&query.getPageSize() !=null){
            PageHelper.startPage(query.getPageNum(),query.getPageSize());
        }

        List<Category> select = categoryDao.select(query);
        if(select instanceof Page){
            Page page= (Page) select;
            Long total= page.getTotal();
            LocalPageInfoutil.set(PageInfo.builder().Total(total).build());
        }
        return select;
    }

    public int insert(Category category){
        return categoryDao.insert(category);
    }
   public int update(Category category){
        return categoryDao.update(category);
    }

    //删除 软删除
   public  int delete(Integer id){
        return categoryDao.updateStatus(id,0);
   }

}
